
jsdom = require('jsdom')

// 生成jsdom对象
const {JSDOM} = jsdom;

const dom = new JSDOM(`<!DOCTYPE html><p>Hello world</p>`);

window = dom.window;
document = dom.document;

// import { JSEncrypt } from "jsencrypt";
var JSEncrypt = require('jsencrypt')

function rsa_en(pubkey, target_str) {
  /**
  分段加密信息
  :params target_str: 需要加密的信息，此处为很长的信息
  :pubkey: 公钥
  :return: 存储密文的数组
  **/
    let encrypt = new JSEncrypt();
    encrypt.setPublicKey(pubkey);
    return encrypt.encrypt(JSON.stringify(target_str));
}
var pk = `-----BEGIN PUBLIC KEY-----
MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCXQA31athdyKAyy1ACbtqvFzQi
7cKBdW7Q1vNW4ukQXsA/Bb5NNquU5bg+eEqvlVgNEgFlRHaBYMidrYo126B53BJD
SREhbkrLogA+ikh2z3+q9deNX+5w5g3i0iOaQIABJVF3XGLv1UMH/DIt+MJiV6Lz
VxqYgYmln5UUYARK/QIDAQAB
-----END PUBLIC KEY-----`
var str = "123"
console.log(rsa_en(pk, str))
